package com.example.mybatisplus.common.utls;

import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.example.mybatisplus.model.domain.UserAccount;

public class SessionUtils {
    private static final String USERKEY = "sessionUser";

    public static HttpSession session() {
        ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
        return attr.getRequest().getSession(true); // true == allow create
    }

	//从session中得到当前登录用户信息
	public static UserAccount getCurrentUserInfo() {
		return (UserAccount) session().getAttribute(USERKEY);
	}

	//将登录的用户信息保存到session中
	public static void saveCurrentUserInfo (UserAccount userAccount) {
		session().setAttribute(USERKEY, userAccount);
	}




}
